<!DOCTYPE html>
<html>

<%@ page import="java.util.ArrayList,java.io.File,org.w3c.dom.*,javax.xml.parsers.*,javax.xml.xpath.*" %>

<% 
	String blume = (request.getParameter("blume"));
	ArrayList <File>allMetaFiles = new ArrayList();
	
	File[] yearLevel = new File("/Users/stephan/Archivtest/archive").listFiles();
	for(File year : yearLevel) {
		if(year.isDirectory()) {
			File[] monthLevel = year.listFiles();
				for(File month : monthLevel) {
					if(month.isDirectory()) {
						File[] dayLevel = month.listFiles();
							for(File day : dayLevel) {
								if(day.isDirectory()) {
									File[] containerLevel = day.listFiles();
										for(File container : containerLevel) {
											if(container.isDirectory()) {
												allMetaFiles.add(container);
											}
									}
								}
							}
					}
				}
		}
	}

	String debug = "";
	//for(File f : allMetaFiles)
	//	debug = debug + " <br> " + f.getName();

	XPath xpath = XPathFactory.newInstance().newXPath();
	XPathExpression expr = xpath.compile("//test/meta[@key='blume' and .='" + blume + "']");
	
	for(File f : allMetaFiles) {
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(new File(f.getAbsolutePath() + "/meta.xml"));
		doc.getDocumentElement().normalize();
		NodeList nodes = (NodeList)(expr.evaluate(doc, XPathConstants.NODESET));
		if(nodes.getLength() > 0) 
			debug = debug + " <br> " + f.getName();	
	}
		

%>

<body>

<h1>Archive test</h1>
<% System.out.println("blume1"); %>

<form method="post" action="index.jsp">
Blume? <input type="text" name="blume" size="20">
<input type="submit">
</form>
<hr>
Count = <%= allMetaFiles.size() %> 
<br>
Debug = <%= debug %>
</body>
</html>